home *** CD-ROM | disk | FTP | other *** search
-
-
- ‹
-
- ‹
-
- åHow Does Menu Events Work?
-
-
-
- When you send a Query Menu List or Query Menu event, the ideal
-
- application will dispatch the resulting high-level event as an Apple event
-
- without looking at it. The event handler provided by Menu Events forms a
-
- reply to the query on the basis of the application’s menu list structure. If
-
- the case of a Query Menu event, if the given menu ID is not valid, it
-
- returns noSuchMenuErr; if the given menu uses a non-standard menu
-
- definition function ('MDEF'), it returns nonStandardMenuErr. Through all
-
- of this, the application stays in the background or in the foreground,
-
- wherever it was before.
-
-
-
- When you send a Select Menu Item event, the same things happen, but the
-
- event handling is more complex.
-
-
- First, it verifies that the given menu item is valid and enabled. If not, it
-
- returns noSuchMenuErr, nonStandardMenuErr, noSuchMenuItemErr, or
-
- menuItemDisabledErr.
-
-
- Second, it asks for the application to be brought to the front for user
-
- interaction, because it could be dangerous to feed the target application a
-
- menu selection while it is in the background, something which never
-
- happens in normal operation. If it is refused, it returns
-
- errAENoUserInteraction.
-
-
- Third, it patches some traps so that it can gain control of menu selection.
-
- If it finds that the patches are already in place, meaning that an earlier
-
- Menu event is still pending, it returns menuEventPendingErr.
-
-
- Fourth, if everything is OK, it posts an event to simulate a mouse click in
-
- the menu bar. The application habitually asks which menu item was
-
- selected, and the patched traps provide the given item in response. The
-
- patches then remove themselves. From there, it is exactly as though the
-
- user had actually made the selection.
-
-
- NOTE: When replying to any of the three event types, Menu Events
-
- includes a null “tattoo” parameter to prove that it handled the event,
-
- rather than some handler supplied by the application. Many Microsoft
-
- applications, for example, bind their own handler over all Apple event
-
- classes, preventing Menu Events from working. (The handler wouldn’t be
-
- a problem if it returned errAEEventNotHandled when faced with an
-
- unknown Apple event, as it should.)
-
-
-
-
- xUser Interaction Policy
-
-
- The Apple Event Manager implements a complicated but sensible model for
-
- joint sender/receiver control over user interaction. Menu Events doesn’t
-
- know which menu selections will really require user interaction, but even
-
- if it did, it would still have to request user interaction just to bring the
-
- target application to the front, where an application always expects to be
-
- when it sees a mouse-down event.
-
-
-
- The sending program must set the kAECanInteract or kAEAlwaysInteract
-
- flag in the sendMode parameter to AESend, in order to achieve user
-
- interaction. It should also set the kAECanSwitchLayer flag, allowing the
-
- target application to come to the front without having to post a
-
- notification request. If the target application is in the background, and
-
- receives a Menu event with this flag not set, it will go into a notification
-
- wait state, which may disrupt its usual background event processing
-
- behavior.
-
-
- If both the sending program and target application are in the background,
-
- the kAECanSwitchLayer flag has no effect, and the notification request is
-
- posted anyway. Since your sending program is indirectly instigating a
-
- user interaction, it should call AEInteractWithUser before sending the
-
- Menu event, if there is any chance that it will be in the background at the
-
- time. Another approach would be to call SetFrontProcess to activate the
-
- target application before sending it a Menu event.
-
-
- If the target application is in that rare user interaction state,
-
- kAEInteractWithSelf, where it disallows interaction requested by any
-
- other process, the Menu event handler will respect that state, and refuse
-
- the event.
-
-
- If the sending and receiving applications are on different machines, the
-
- usual program linking checks apply, namely, Sharing Setup (on/off),
-
- Users & Groups (permission to user), and Finder’s Sharing (permission to
-
- application).
-
-
- If the Menu Events extension is locked, using Finder’s Get Info dialog, then
-
- only target applications which explicitly allow interaction with all
-
- processes can be controlled by remote senders. If it is not locked, and if
-
- it sees that the user interaction state is kAEInteractWithLocal, which is
-
- the default value, it will momentarily change it to kAEInteractWithAll, so
-
- that events sent from a remote machine are not rejected. This trick is
-
- necessary for Menu Events to be useful with most target applications,
-
- because most will assume the default interaction state, not expecting any
-
- remote sender to require user interaction. The icon displayed by Menu
-
- Events at startup shows whether or not the lock is in effect.
-
-
- IMPORTANT NOTE: Users of machines where Menu Events is installed
-
- should be careful about which users and applications are enabled for
-
- remote program linking. In particular, guest users should not be allowed
-
- to do program linking unless Menu Events is locked.
-
-
-
-